package yang.yu.sessioncache.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * Created by yyang on 15/9/8.
 */
public class JedisTemplate {

    private JedisPool jedisPool;

    public JedisTemplate(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }

    public <T> T execute(JedisCallback<T> callback) {
        try(Jedis jedis = jedisPool.getResource()) {
            return callback.doInRedis(jedis);
        }
    }
}
